package com.hnkywl.sts.action.kcgl;

import com.hnkywl.sts.entity.cggl.Cgd;
import com.hnkywl.sts.entity.cggl.Cgdmx;
import com.hnkywl.sts.entity.cggl.Dhd;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.service.cggl.CgdService;
import com.hnkywl.sts.service.cggl.CgdmxService;
import com.hnkywl.sts.service.kcgl.DhdService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.sys.YgService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-4-15
 * Time: 下午2:17
 * To change this template use File | Settings | File Templates.
 */

@Namespace("/kcgl/dhd")
public class DhdAction extends SimpleActionSupport {
    private DhdService dhdService;
    private CgdmxService cgdmxService;
    //页面当前位置
    private int page;
    //每页行数
    private int rows;
    //行索引
    private int index;
    private Date sysdate;
    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;
    private Dhd dhd;
    private Long dhdId;
    private String dlrName;
    private Long rkshId;
    private Cgd rksh;
    private Date sysTime;
    private Long wzId;
    private String wzCode = "";
    private String wzName = "";
    private String wzGgxh = "";
    private String dw = "";
    private String cd = "";
    private String type;
    private String GurrentName;
    private CgdService cgdService;
    private Long cgdId;
    private Long cgdmxId;
    private Double yssl;
    private Cgdmx cgdmx;


    //实时库存列表
    @Action("dhdList")
    public void dhdList() {
        this.renderJson(this.dhdService.findAllDhd(cgdId, cgdmxId, 0, 10));
    }

    @Actions({@Action("rksh_dhd_content"), @Action("rksh_dhd_detail")})
    public String dhdContent() {
        sysTime = new Date();
        rksh = cgdService.findByCgdmxId(cgdmxId);
        cgdmx = cgdmxService.findCgdmxById(cgdmxId);
        GurrentName = YgService.getCurrentYgName();
        dhdId = dhdService.findDhdIdByCgdmxId(cgdmxId);
        if (dhdId != -1l) {
            dhd = dhdService.findDhdDetail(dhdId);
        } else {
            dhd = new Dhd();
        }
        return SUCCESS;
    }

    @Action("add_dhd")
    public void addDhd() {
        try {
            dhdService.saveDhd(dhd);
            renderText("{\"statusCode\":\"200\", \"message\":\"保存到货单信息成功\", \"operationType\":\"add\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("update_dhd")
    public void updateDhd() {
        try {
            this.dhdService.updateDhd(dhd);
            renderText("{\"statusCode\":\"200\", \"message\":\"修改到货单成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("delete_dhd")
    public void deleteDhd() {
        try {
            dhdService.deleteDhd(dhdId);
            renderJson("{\"statusCode\":\"200\", \"message\":\"删除到货单成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    @Action("dhd_detail")
    public void dhdDetail() {
        this.renderJson(this.dhdService.findDhdById(dhdId));
    }

    public Long getDhdId() {
        return dhdId;
    }

    public void setDhdId(Long dhdId) {
        this.dhdId = dhdId;
    }

    public Double getYssl() {
        return yssl;
    }

    public void setYssl(Double yssl) {
        this.yssl = yssl;
    }

    public int getPage() {
        return page;
    }

    public Long getRkshId() {
        return rkshId;
    }

    public Long getCgdmxId() {
        return cgdmxId;
    }

    public void setCgdmxId(Long cgdmxId) {
        this.cgdmxId = cgdmxId;
    }

    public String getGurrentName() {
        return GurrentName;
    }

    public void setGurrentName(String gurrentName) {
        GurrentName = gurrentName;
    }

    public void setRkshId(Long rkshId) {
        this.rkshId = rkshId;
    }

    public Date getSysTime() {
        return sysTime;
    }

    public void setSysTime(Date sysTime) {
        this.sysTime = sysTime;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Date getSysdate() {
        return sysdate;
    }

    public void setSysdate(Date sysdate) {
        this.sysdate = sysdate;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    public GnczService getGnczService() {
        return gnczService;
    }

    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }

    public Dhd getDhd() {
        return dhd;
    }

    public void setDhd(Dhd dhd) {
        this.dhd = dhd;
    }

    public Long getWzId() {
        return wzId;
    }

    public void setWzId(Long wzId) {
        this.wzId = wzId;
    }

    public String getWzCode() {
        return wzCode;
    }

    public void setWzCode(String wzCode) {
        this.wzCode = wzCode;
    }

    public String getWzName() {
        return wzName;
    }

    public void setWzName(String wzName) {
        this.wzName = wzName;
    }

    public String getWzGgxh() {
        return wzGgxh;
    }

    public void setWzGgxh(String wzGgxh) {
        this.wzGgxh = wzGgxh;
    }

    public String getDw() {
        return dw;
    }

    public void setDw(String dw) {
        this.dw = dw;
    }

    public String getCd() {
        return cd;
    }

    public void setCd(String cd) {
        this.cd = cd;
    }

    public String getDlrName() {
        return dlrName;
    }

    public void setDlrName(String dlrName) {
        this.dlrName = dlrName;
    }

    public Cgd getRksh() {
        return rksh;
    }

    public void setRksh(Cgd rksh) {
        this.rksh = rksh;
    }

    public Long getCgdId() {
        return cgdId;
    }

    public void setCgdId(Long cgdId) {
        this.cgdId = cgdId;
    }

    public Cgdmx getCgdmx() {
        return cgdmx;
    }

    public void setCgdmx(Cgdmx cgdmx) {
        this.cgdmx = cgdmx;
    }

    @Autowired
    public void setDhdService(DhdService dhdService) {
        this.dhdService = dhdService;
    }

    @Autowired
    public void setCgdService(CgdService cgdService) {
        this.cgdService = cgdService;
    }

    @Autowired
    public void setCgdmxService(CgdmxService cgdmxService) {
        this.cgdmxService = cgdmxService;
    }
}
